package wiki.generic.concretemed;

import java.util.HashMap;

import wiki.generic.io.Element;
import wiki.generic.io.ElementsMapReader;
import wiki.generic.io.GenericDataWriter;
import wiki.generic.io.MapDataReader;
import wiki.generic.io.PathKeeper;
import wiki.generic.io.PropertiesReader;
import wiki.generic.layout.LayoutPrototypeFactory;
import wiki.generic.layout.LayoutPrototypeWriter;
import wiki.generic.managers.PropertiesManager;
import wiki.generic.med.ViewingService;

/**
 * 
 * @author <p><strong>JwTeam</strong></p> 
 *
 */
public class ViewingServiceMediator implements ViewingService {

	private PropertiesReader proprietiesReader;
	private GenericDataWriter proprietesWriter;
	private PathKeeper smap;
	private LayoutPrototypeFactory lfactory;
	private ElementsMapReader elreader;
	private PathKeeper elmap;
	private MapDataReader coursesReader;


	public ViewingServiceMediator(PropertiesReader proprietiesReader,
			GenericDataWriter proDataWriter, PathKeeper map,
			ElementsMapReader elreader, PathKeeper elmap, MapDataReader coursesReader ) {
		this.proprietiesReader = proprietiesReader;
		this.proprietesWriter = proDataWriter;
		this.smap = map;
		this.elreader=elreader;
		this.elmap=elmap;
		this.coursesReader=coursesReader;
		PropertiesManager.getPropertiesManager().setMap(
				proprietiesReader.getPropMap(coursesReader.getMap()));
		}

	public void setLfactory(LayoutPrototypeFactory lfactory) {
		this.lfactory = lfactory;
	}

	
	@Override
	public void setParameter(String corso,String id, String value) {
		PropertiesManager.getPropertiesManager().getMap().get(corso).changeParameter(id, value);
		proprietesWriter.saveDataMap(PropertiesManager.getPropertiesManager()
				.getMap().get(corso).getMap(), coursesReader.getMap().get(corso)+"/"+proprietiesReader.getFile());

	}

	public String getParameter(String corso,String id) {
		return PropertiesManager.getPropertiesManager().getMap().get(corso).getParameterbyId(id);
	}

	public HashMap<String, String> getStyleMap() {
		return smap.getPathMap();
	}

	public LayoutPrototypeWriter getLayoutWriter(String layout) {
		return lfactory.generateLayoutPrototypeWriter(layout);
	}

	

	
	public Element getContentMainParameterbyID(String type, int ID){
		HashMap<Integer, Element> map=getElementsMapbyType(type);
		return map.get(ID);
	}

	

	public HashMap<Integer, Element> getElementsMapbyType(String type){
		String path=elmap.getPathMap().get(type);
		return elreader.getElementsMap(path);
	}

	
}
